Example - Function with Arguments

An Example showing how it works.

Description: The following example demonstrates how to pass arguments into a DOS function. The :myDosFunc function is being called multiple times with different arguments.

Note: The last call to myDosFunc doesn`t use double quotes for the second argument. Subsequently "for" and "me" will be handled as two separate arguments, whereas the third argument "me" is not being used within the function.
Script: Download: BatchTutoFunc2.bat  
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
@echo off

echo.going to execute myDosFunc with different arguments
call:myDosFunc 100 YeePEE
call:myDosFunc 100 "for me"
call:myDosFunc 100,"for me"
call:myDosFunc 100,for me

echo.&pause&goto:eof


::--------------------------------------------------------
::-- Function section starts below here
::--------------------------------------------------------

:myDosFunc    - here starts my function identified by it's label
echo.
echo. here the myDosFunc function is executing a group of commands
echo. it could do %~1 of things %~2.
goto:eof
Script Output:
 DOS Script Output
going to execute myDosFunc with different arguments

 here the myDosFunc function is executing a group of commands
 it could do 100 of things YeePEE.

 here the myDosFunc function is executing a group of commands
 it could do 100 of things for me.

 here the myDosFunc function is executing a group of commands
 it could do 100 of things for me.

 here the myDosFunc function is executing a group of commands
 it could do 100 of things for.

Press any key to continue . . .